//
//  DDHomeViewController.m
//  Dingdong
//
//  Created by 程强 on 16/11/11.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDHomeViewController.h"
#import "ImageScrollView.h"
#import "DDMenuView.h"
#import "DFWHomeOptionalView.h"
#import "UIImage+Extension.h"
#import "DDSearchViewController.h"
#import "DDHomeManager.h"
#import "DDCarouselSet.h"
#import "DDBotPitObj.h"
#import "DDHotSaleSet.h"
#import "DDSixCollectionCell.h"
#import "DDTopHotGoodsSet.h"
#import "DDHomeAdsSet.h"
#import "DDHotSaleCollectionCell.h"
#import "MJRefresh.h"
#import "DDHotSaleCollectionHeaderView.h"
#import "DDHomeCategorySet.h"
#import "DDGoodsDetailsViewController.h"
#import "UIView+Touch.h"
#import "DDGoodsListViewController.h"
#import "DDMessageViewController.h"

@interface DDHomeViewController ()<UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,DFWHomeOptionalViewDelegate,DDMenuViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *bgScrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollWidth;
@property (assign, nonatomic) BOOL naviBarLight;
#pragma mark --- 轮播图
@property (weak, nonatomic) IBOutlet UIView *topCarouselBgView;
@property (strong, nonatomic) ImageScrollView *topCarouselView;
#pragma mark --- 菜单
@property (weak, nonatomic) IBOutlet UIView *menuBgView;
@property (strong, nonatomic) DDMenuView *menuView;
#pragma mark --- 商品滚动图
@property (weak, nonatomic) IBOutlet UIView *optionBgView;
@property (strong, nonatomic) DFWHomeOptionalView *optionView;
#pragma mark --- 3商品组合图
@property (weak, nonatomic) IBOutlet UIView *firstGroupBgView;
@property (weak, nonatomic) IBOutlet UIImageView *horTopAdImage;
@property (weak, nonatomic) IBOutlet UIImageView *horBotAdImage;
@property (weak, nonatomic) IBOutlet UIImageView *verRightAdImage;
#pragma mark --- 1+1广告位
@property (weak, nonatomic) IBOutlet UIView *secondGroupBgView;
@property (weak, nonatomic) IBOutlet UIImageView *sec_leftImage;
@property (weak, nonatomic) IBOutlet UIImageView *sec_rightImage;
#pragma mark --- 中间轮播图
@property (weak, nonatomic) IBOutlet UIView *midCarouselBgView;
@property (weak, nonatomic) IBOutlet UIImageView *midBanner;
#pragma mark --- 6个商品组
@property (weak, nonatomic) IBOutlet UIView *sixGroupBgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *sixGroupBgViewHeight;
@property (weak, nonatomic) IBOutlet UICollectionView *sixGroupCollection;
#pragma mark --- 底部banner
@property (weak, nonatomic) IBOutlet UIImageView *botBanner;
#pragma mark --- banner下面的横向商品列表
@property (weak, nonatomic) IBOutlet UIView *botHorGoodsBgView;
@property (strong, nonatomic) DFWHomeOptionalView *botHorOptionView;
#pragma mark --- 热销商品列表
@property (weak, nonatomic) IBOutlet UICollectionView *hotSaleCollection;
@property (assign, nonatomic) NSInteger currentPage;

@property (strong, nonatomic) DDHomeManager *manager;
#pragma mark --- 数据源
@property (strong, nonatomic) DDCarouselSet *topCarouselSet;
@property (strong, nonatomic) DDHomeCategorySet *homeCategorySet;
@property (strong, nonatomic) DDTopHotGoodsSet *topHotSet;
@property (strong, nonatomic) DDHomeAdsSet *homeAdsSet;
@property (strong, nonatomic) DDBotPitObj *botPitObj;/**<底部带banner的横向商品列表*/
@property (strong, nonatomic) DDHotSaleSet *hotSaleGroup;/**<6个商品组*/
@end

@implementation DDHomeViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.manager = [DDHomeManager new];
    [self layoutHomeView];
    [self clearNavigationBar];
    [self getTopCarousel];
    [self getCategory];
    [self getHorizontalGoodsWithBanner];
    [self getTopHotGoods];
    [self getAllAds];
}
- (void)clearNavigationBar
{
    self.navBarView.backgroundColor = [UIColor clearColor];
}
- (void)gotoMessage
{
    DDMessageViewController *vc = StoryBoardViewController(@"Setting", @"DDMessageViewController");
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)layoutHomeView
{
    UIImage *logo = [LoadImage(@"home_logo") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftBar = [[UIBarButtonItem alloc]initWithImage:logo style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.leftBarButtonItem = leftBar;
    
    UIImage *msg_icon = [LoadImage(@"home_msg") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithImage:msg_icon style:UIBarButtonItemStylePlain target:self action:@selector(gotoMessage)];
    self.navigationItem.rightBarButtonItem = rightBar;
    
    [self titleSearchBar];
    
    //顶部的轮播图
    self.topCarouselView = [[ImageScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth*(8/15.0))];
    _topCarouselView.pics = @[];
    _topCarouselView.placePics = @[];
    _topCarouselView.autoScroll = YES;
    [self.topCarouselBgView addSubview:_topCarouselView];
    [_topCarouselView reloadView];
    [_topCarouselView returnIndex:^(NSInteger index) {
        DDCarouselObj *obj = _topCarouselView.dataAry[index];
        [self gotoGoodsDetailsController:@([obj.url integerValue])];
    }];
    
    self.menuView = [[DDMenuView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 70)];
    _menuView.delegate = self;
    [self.menuBgView addSubview:_menuView];
    
    self.optionView = [[DFWHomeOptionalView alloc]initWithFrame:CGRectMake(0, 30, ScreenWidth, 160)];
    _optionView.delegate = self;
    [self.optionBgView addSubview:_optionView];
    
    self.botHorOptionView = [[DFWHomeOptionalView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 170)];
    _botHorOptionView.delegate = self;
    [self.botHorGoodsBgView addSubview:_botHorOptionView];
    
    [self setRefresh];
    self.scrollWidth.constant = ScreenWidth;
    self.scrollHeight.constant = 1475;
    
    self.horTopAdImage.canTouch = @"yes";
    self.horBotAdImage.canTouch = @"yes";
    self.verRightAdImage.canTouch = @"yes";
    self.sec_leftImage.canTouch = @"yes";
    self.sec_rightImage.canTouch = @"yes";
    self.botBanner.canTouch = @"yes";
    self.midBanner.canTouch = @"yes";
}
- (void)menu:(DDMenuView *)menu didSelectMenuIndex:(NSInteger)index
{
    DDHomeCategoryObj *category = self.homeCategorySet.categoryAry[index];
    DDGoodsListViewController *vc = StoryBoardViewController(@"Shop", @"DDGoodsListViewController");
    vc.category_id = @([category.url integerValue]);
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)optionalView:(DFWHomeOptionalView *)view didSelectIndex:(NSInteger)index
{
    NSNumber *goods_id = @0;
    if (view == self.optionView) {
        DDGoodsObj *goods = self.optionView.dataAry[index];
        goods_id = goods.goods_id;
    }else{
        DDGoodsObj *goods = self.botHorOptionView.dataAry[index];
        goods_id = goods.goods_id;
    }
    [self gotoGoodsDetailsController:goods_id];
}
- (void)setRefresh
{
    weak_Self(self);
    MJRefreshHeader *header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf headerRefresh];
    }];
    MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        [weakSelf footerRefresh];
    }];
    [self.bgScrollView setMj_header:header];
    [self.bgScrollView setMj_footer:footer];
    [self headerRefresh];
}
- (void)headerRefresh
{
    self.currentPage = 1;
    weak_Self(self);
    [self getVerticalGoodsWithPageNo:self.currentPage pageSize:kPageSize pull:YES complete:^{
        [weakSelf.bgScrollView.mj_header endRefreshing];
    }];
}
- (void)footerRefresh
{
    weak_Self(self);
    [self getVerticalGoodsWithPageNo:self.currentPage pageSize:kPageSize pull:NO complete:^{
        [weakSelf.bgScrollView.mj_footer endRefreshing];
    }];
}
- (void)titleSearchBar
{
    UIButton *bgView = [[UIButton alloc]initWithFrame:CGRectMake(80, 7, ScreenWidth-160, 30)];
    bgView.backgroundColor = [RGBColor(200, 200, 200) colorWithAlphaComponent:0.6];
    bgView.layer.cornerRadius = 3.0;
    self.navigationItem.titleView = bgView;
    [bgView addTarget:self action:@selector(gotoSearch:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *searchIcon = [[UIImageView alloc]initWithImage:LoadImage(@"home_sousuo")];
    [searchIcon setFrame:CGRectMake(ScreenWidth-190, 5, 20, 20)];
    [bgView addSubview:searchIcon];
}
- (void)gotoSearch:(UIButton *)sender
{
    DDSearchViewController *vc = [[DDSearchViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:NO];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY > NAVBAR_CHANGE_POINT) {
        CGFloat alpha = MIN(0.7, 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64));
        self.navBarView.backgroundColor = BXAlphaColor(255, 255, 255, alpha);
        if (_naviBarLight) {
            UIImage *msg_icon = [LoadImage(@"home_msg_black") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithImage:msg_icon style:UIBarButtonItemStylePlain target:self action:@selector(gotoMessage)];
            self.navigationItem.rightBarButtonItem = rightBar;
        }
        self.naviBarLight = NO;
    } else {
        if (!_naviBarLight) {
            self.navBarView.backgroundColor = BXAlphaColor(255, 255, 255, 0);
            UIImage *msg_icon = [LoadImage(@"home_msg") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
            UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithImage:msg_icon style:UIBarButtonItemStylePlain target:self action:@selector(gotoMessage)];
            self.navigationItem.rightBarButtonItem = rightBar;
        }
        _naviBarLight = YES;
    }
}

#pragma mark --- UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (collectionView == self.sixGroupCollection) {
        return self.homeAdsSet.sixAdsAry.count;
    }else{
        return self.hotSaleGroup.goodsGroup.count;
    }
    return 0;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView == self.sixGroupCollection) {
        DDSixCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SixCell" forIndexPath:indexPath];
        DDHomeAdsObj *obj = self.homeAdsSet.sixAdsAry[indexPath.row];
        [cell.goodsIcon sd_setImageWithURL:[NSURL URLWithString:obj.atturl] placeholderImage:nil];
        cell.goodsNameLbl.text = obj.aname;
        return cell;
    }else{
        DDHotSaleCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotSaleCell" forIndexPath:indexPath];
        DDGoodsObj *obj = self.hotSaleGroup.goodsGroup[indexPath.row];
        [cell.hotSaleGoodsIcon sd_setImageWithURL:[NSURL URLWithString:obj.thumbnail] placeholderImage:nil];
        cell.hotSaleGoodsName.text = obj.name;
        cell.hotSaleGoodsPrice.text = FormatString(@"$%.2f", [obj.price doubleValue]);
        return cell;
    }
    return nil;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSNumber *xid = @0;
    if (collectionView == self.sixGroupCollection) {
        DDHomeAdsObj *obj = self.homeAdsSet.sixAdsAry[indexPath.row];
        xid = @([obj.url integerValue]);
    }else{
        DDGoodsObj *obj = self.hotSaleGroup.goodsGroup[indexPath.row];
        xid = obj.goods_id;
    }
    [self gotoGoodsDetailsController:xid];
}
#pragma mark ---- UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView == self.sixGroupCollection) {
        CGFloat width = (ScreenWidth-4)/3.0;
        CGFloat height = width;
        return (CGSize){width,height};
    }else{
        CGFloat width = (ScreenWidth-10)/2.0;
        CGFloat height = width+50;
        return (CGSize){width,height};
    }
    return CGSizeZero;
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (collectionView == self.sixGroupCollection) {
        return UIEdgeInsetsMake(1,1, 1, 1);
    }else{
        return UIEdgeInsetsMake(5, 2, 5, 2);
    }
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    if (collectionView == self.sixGroupCollection) {
        return 1.f;
    }else{
        return 5.0f;
    }
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    if (collectionView == self.sixGroupCollection) {
        return 1.f;
    }else{
        return 5.0f;
    }
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionReusableView *reusableView = nil;
    
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        if (collectionView == self.hotSaleCollection) {
            DDHotSaleCollectionHeaderView * header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HotSaleHeader" forIndexPath:indexPath];
            reusableView = header;
        }
    }
    return reusableView;
}

#pragma mark --- 接口
//顶部轮播图
- (void)getTopCarousel
{
    weak_Self(self);
    [[self.manager getHomeTopCarousel]subscribeNext:^(id x) {
        weakSelf.topCarouselSet = x;
        weakSelf.topCarouselView.dataAry = [x carouselAry];
        [weakSelf reloadTopCarousel];
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}
- (void)reloadTopCarousel
{
    __block NSMutableArray *picAry = [[NSMutableArray alloc]initWithCapacity:0];
    [self.topCarouselSet.carouselAry enumerateObjectsUsingBlock:^(DDCarouselObj * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        DDCarouselObj *cobj = obj;
        [picAry addObject:ValidString(cobj.atturl)];
    }];
    _topCarouselView.pics =picAry;
    [_topCarouselView reloadView];
}
//首页类目
- (void)getCategory
{
    weak_Self(self);
    [[self.manager getHomeCategory]subscribeNext:^(id x) {
        weakSelf.homeCategorySet = x;
        [weakSelf reloadCategory];
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}
- (void)reloadCategory
{
    self.menuView.menus = self.homeCategorySet.categoryAry;
}
//顶部爆款推荐
- (void)getTopHotGoods
{
    weak_Self(self);
    [[self.manager getTopHotGoodsList]subscribeNext:^(id x) {
        weakSelf.topHotSet = x;
        [weakSelf reloadTopHotGoods];
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}
- (void)reloadTopHotGoods
{
    self.optionView.dataAry = self.topHotSet.goodsAry;
}
//广告位
- (void)getAllAds
{
    weak_Self(self);
    [[self.manager homtAdsList]subscribeNext:^(id x) {
        weakSelf.homeAdsSet = x;
        [weakSelf reloadAdsInfo];
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}
- (void)reloadAdsInfo
{
    __block NSMutableArray *temp1_ary = [[NSMutableArray alloc]initWithCapacity:0];
    __block NSMutableArray *temp2_ary = [[NSMutableArray alloc]initWithCapacity:0];
    __block NSMutableArray *temp3_ary = [[NSMutableArray alloc]initWithCapacity:0];
    __block NSMutableArray *temp4_ary = [[NSMutableArray alloc]initWithCapacity:0];
    [self.homeAdsSet.adsAry enumerateObjectsUsingBlock:^(DDHomeAdsObj * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       
        if ([obj.cname isEqualToString:@"2+1广告位"]) {
            [temp1_ary addObject:obj];
        }else if ([obj.cname isEqualToString:@"1+1广告位"]){
            [temp2_ary addObject:obj];
        }else if ([obj.cname isEqualToString:@"3X2广告位"]){
            [temp3_ary addObject:obj];
        }else if ([obj.cname isEqualToString:@"通栏banner"]){
            [temp4_ary addObject:obj];
        }
        
    }];
    self.homeAdsSet.threeAdsAry = temp1_ary;
    self.homeAdsSet.twoAdsAry = temp2_ary;
    self.homeAdsSet.sixAdsAry = temp3_ary;
    self.homeAdsSet.bannerAdsAry = temp4_ary;
    
    //2+1广告位
    [self.homeAdsSet.threeAdsAry enumerateObjectsUsingBlock:^(DDHomeAdsObj * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            [self.verRightAdImage sd_setImageWithURL:[NSURL URLWithString:obj.atturl] placeholderImage:nil];
        }else if (idx == 1){
            [self.horTopAdImage sd_setImageWithURL:[NSURL URLWithString:obj.atturl] placeholderImage:nil];
        }else if (idx == 2){
            [self.horBotAdImage sd_setImageWithURL:[NSURL URLWithString:obj.atturl] placeholderImage:nil];
        }
    }];
    
    [self.verRightAdImage touchViewHandler:^{
        if (self.homeAdsSet.threeAdsAry.count>0) {
            DDHomeAdsObj *obj = self.homeAdsSet.threeAdsAry[0];
            [self gotoGoodsDetailsController:@([obj.url integerValue])];
        }
    }];
    [self.horTopAdImage touchViewHandler:^{
        if (self.homeAdsSet.threeAdsAry.count>1) {
            DDHomeAdsObj *obj = self.homeAdsSet.threeAdsAry[1];
            [self gotoGoodsDetailsController:@([obj.url integerValue])];
        }
    }];
    [self.horBotAdImage touchViewHandler:^{
        if (self.homeAdsSet.threeAdsAry.count>2) {
            DDHomeAdsObj *obj = self.homeAdsSet.threeAdsAry[2];
            [self gotoGoodsDetailsController:@([obj.url integerValue])];
        }
    }];
    
    //1+1广告位
    [self.homeAdsSet.twoAdsAry enumerateObjectsUsingBlock:^(DDHomeAdsObj * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            [self.sec_leftImage sd_setImageWithURL:[NSURL URLWithString:obj.atturl] placeholderImage:nil];
        }else if (idx == 1){
            [self.sec_rightImage sd_setImageWithURL:[NSURL URLWithString:obj.atturl] placeholderImage:nil];
        }
    }];
    
    [self.sec_leftImage touchViewHandler:^{
        if (self.homeAdsSet.twoAdsAry.count>0) {
            DDHomeAdsObj *obj = self.homeAdsSet.twoAdsAry[0];
            [self gotoGoodsDetailsController:@([obj.url integerValue])];
        }
    }];
    [self.sec_rightImage touchViewHandler:^{
        if (self.homeAdsSet.twoAdsAry.count>1) {
            DDHomeAdsObj *obj = self.homeAdsSet.twoAdsAry[1];
            [self gotoGoodsDetailsController:@([obj.url integerValue])];
        }
    }];
    
    CGFloat width = (ScreenWidth-4)/3.0;
    [self.sixGroupCollection reloadData];
    self.sixGroupBgViewHeight.constant = (width+1)*2;
    
    if (self.homeAdsSet.bannerAdsAry.count>0) {
        [self.midBanner sd_setImageWithURL:[NSURL URLWithString:[self.homeAdsSet.bannerAdsAry[0] atturl]] placeholderImage:nil];
        [self.midBanner touchViewHandler:^{
            DDHomeAdsObj *obj = self.homeAdsSet.bannerAdsAry[0];
            [self gotoGoodsDetailsController:@([obj.url integerValue])];
        }];
    }

}
- (void)getHorizontalGoodsWithBanner
{
    weak_Self(self);
    [[self.manager getHomeHorizontalGoodsWithBanner]subscribeNext:^(id x) {
        weakSelf.botPitObj = x;
        [weakSelf reloadBotPitInfo];
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}
- (void)reloadBotPitInfo
{
    [self.botBanner sd_setImageWithURL:[NSURL URLWithString:self.botPitObj.imageurl] placeholderImage:nil];
    [self.botBanner touchViewHandler:^{
        NSNumber *goods_id =@([self.botPitObj.flag integerValue]);
        [self gotoGoodsDetailsController:goods_id];
    }];
    self.botHorOptionView.dataAry = self.botPitObj.goodsMap;
}
- (void)getVerticalGoodsWithPageNo:(NSInteger)pageNo pageSize:(NSInteger)size pull:(BOOL)pull complete:(void(^)())block
{
    weak_Self(self);
    if (pull) {
        self.currentPage = 1;
    }
    [[self.manager getHomeVerticalGoodsListWithPageNo:pageNo size:size]subscribeNext:^(id x) {
        if (pull) {
            [weakSelf.hotSaleGroup.goodsGroup removeAllObjects];
            weakSelf.hotSaleGroup = x;
        }else{
            DDHotSaleSet *set = x;
            [weakSelf.hotSaleGroup.goodsGroup addObjectsFromArray:set.goodsGroup];
        }
        [weakSelf reloadVerticalGoods];
        weakSelf.currentPage+=1;
    } error:^(NSError *error) {
        
    } completed:^{
        if (block) {
            block();
        }
    }];
}
- (void)reloadVerticalGoods
{
    [self.hotSaleCollection reloadData];
    CGFloat height = 0;
    NSInteger row = 0;
    NSInteger remainder = self.hotSaleGroup.goodsGroup.count%2;
    if (remainder == 0) {
        row =self.hotSaleGroup.goodsGroup.count/2;
    }else{
        row =self.hotSaleGroup.goodsGroup.count/2+1;
    }
    CGFloat width = (ScreenWidth-10)/2.0;
    CGFloat cellHeight = width+50;
    height = (cellHeight+5)*row+50;
    self.scrollHeight.constant=height+1475;
}
- (void)gotoGoodsDetailsController:(NSNumber *)goods_id
{
    DDGoodsDetailsViewController *vc = [[DDGoodsDetailsViewController alloc]init];
    vc.goods_id = goods_id;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
